<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Course;

/**
 * CourseSearch represents the model behind the search form of `backend\models\Course`.
 */
class CourseSearch extends Course
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ID', 'XXID', 'ZXS', 'LLXS', 'SYXS', 'SJXS'], 'integer'],
            [['KCMC', 'KCDM', 'KCLB', 'KCXZ', 'KCJJ', 'KHFS', 'JXDG', 'JC', 'CJSJ', 'GXSJ'], 'safe'],
            [['XF'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Course::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ID' => $this->ID,
            'XXID' => $this->XXID,
            'XF' => $this->XF,
            'ZXS' => $this->ZXS,
            'LLXS' => $this->LLXS,
            'SYXS' => $this->SYXS,
            'SJXS' => $this->SJXS,
            'CJSJ' => $this->CJSJ,
            'GXSJ' => $this->GXSJ,
        ]);

        $query->andFilterWhere(['like', 'KCMC', $this->KCMC])
            ->andFilterWhere(['like', 'KCDM', $this->KCDM])
            ->andFilterWhere(['like', 'KCLB', $this->KCLB])
            ->andFilterWhere(['like', 'KCXZ', $this->KCXZ])
            ->andFilterWhere(['like', 'KCJJ', $this->KCJJ])
            ->andFilterWhere(['like', 'KHFS', $this->KHFS])
            ->andFilterWhere(['like', 'JXDG', $this->JXDG])
            ->andFilterWhere(['like', 'JC', $this->JC]);

        return $dataProvider;
    }
}
